<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
//if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
if(userInfo.getRoleId()!=com.jxtti.utils.Constants.AdminRole){ //非超管
	orgId=userInfo.getOrgId().toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>文章类目列表</title>
		<%@ include file="../../../common/Admin-list.jsp"%> 	
 		<script type="text/javascript">
			$(function(){
				//功能菜单
			var toolbars=[{
					text: '新增一级类目', 
					iconCls: 'icon-add',
					handler: function(){	
						art.dialog.open('../ArticleCategory/addInterface.htm?type=add&parentID=0',{
									title: '',
									lock:true,
								  	width: '50%',
								    height: '70%'												   												   
								});
					}
				},'-', {
	                text : '展开',
	                iconCls : 'icon-redo',
	                handler : function() {
	                    var node = $('#tg').treegrid('getSelected');		                  
	                    if (node) {		                    	
	                        $('#tg').treegrid('expand', node.id);
	                    } else {		                    	
	                        $('#tg').treegrid('expandAll');
	                    }
	                }
	            }, '-', {
	                text : '折叠',
	                iconCls : 'icon-undo',
	                handler : function() {
	                    var node = $('#tg').treegrid('getSelected');
	                    if (node) {
	                        $('#tg').treegrid('collapseAll', node.id);
	                    } else {
	                        $('#tg').treegrid('collapseAll');
	                    }
	                }
	            }, '-', {
	                text : '刷新',
	                iconCls : 'icon-reload',
	                handler : function() {
	                    $('#tg').treegrid('reload');
	                }
	            }] ;
				
				if(<%=orgId %>!=null){ //是否管理员				
					toolbars.shift();//删除第一项
				}				
				
				$('#tg').treegrid({									
					height:'500',					
					rownumbers: true,
					animate:true,
					collapsible:true,
					fitColumns:true,					
					url:'../ArticleCategory/getEasyUiTree.json?noAdmin=yes',
					method: 'post',
					idField: 'id',
					treeField: 'name',		
					lines: true,
					showFooter:true,
					onLoadSuccess: function () {
						if(<%=orgId %>==null){ //是否管理员				
							$('#tg').treegrid('collapseAll');
						}	
					},
					toolbar:toolbars,					
					columns:[[
						{title:'id',field:'id',hidden:true,width:10},
						{title:'parentID',field:'parentID',hidden:true,width:10},
						{title:'levelID',field:'levelID',hidden:true,width:10},
						{title:'编码',field:'code',hidden:true,width:100},	
						{title:'名称',field:'name',width:100},		 
						{title:'科室ID',field:'fk_orgId',hidden:true,width:100},		 
						{title:'所属科室',field:'orgIdName',width:100},
						{title:'开放投稿',field:'is_contribute',width:30,align:'center',
							formatter:function(value){									
					    		if(value=="1"){
					    			return '<font color="red">√</font> ';
					    		}else{
					    			return '';
					    		}						    							    	
					    	}	
						},
						{title:'路径',field:'url',width:100,
							//预览
							formatter:function(value,rec,index){	
								var url="/SiteIndex/category.htm?id="+encode64((rec.id).toString());								
					    		var html='<a href="<%=basePath %>'+url+'" target="_blank"><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a>'+url;
						    	return html;						    	
					    	}
						},		
						{title:'显示',field:'visible',width:20,align:'center',
						    formatter:function(value){						    	
						    	if (value){
						    		var ss;
						    		if(value=="1"){
						    			ss='<span disabled="disabled"><input type="checkbox" checked="checked" disabled="disabled"></span> ';
						    		}else{
						    			ss='<span disabled="disabled"><input type="checkbox" disabled="disabled"></span> ';
						    		}
							    	return ss;
						    	} else {
							    	return '';
						    	}
					    	}
						},							
						{title:'排序',field:'sortID',width:20,align:'center'},
						{field:'opt',title:'操作',width:100,align:'left',  
		                    formatter:function(value,rec,index){
		                    	
		                    	var up='<a title="上移" href="#" onclick="UpDown(\''+ rec.id + '\','+(Number(rec.sortID)-1)+')">' +
		                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/up.gif" alt="Up"></a>&nbsp;&nbsp;';
		                    			
                    			var down='<a title="下移" href="javascript:UpDown(\''+ rec.id + '\','+(Number(rec.sortID)+1)+')">' +
                    					'<img src="<%=basePath %>pages/Admin/Images/Icon/down.gif" alt="Down"></a>&nbsp;&nbsp;';
                   			
		                    	var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\')"  href="#">'+
		                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
		                    	
		                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+
		                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';
		                        
		                        // 判断是否 parentID=0 则有增加 下一级的 按钮 levelID
		                        var add='<a title="新增子级" onclick="addSub(\''+ rec.id + '\',\''+rec.levelID+'\',\''+rec.fk_orgId+'\')" href="#">'+
		                        			'<img src="<%=basePath %>pages/Admin/Images/Icon/add.gif" alt="Add"></a>&nbsp;&nbsp;';
		                        return up+down+edit+dele+add;  
		                    }  
		                 }  
						
					]]				
				});
			})
			
			//排序 
			function UpDown(pkMenu,newSort){  								
				$.ajax({  
					type: "POST",  
			        url: '../ArticleCategory/update.json', 
		    	    data:{  
		    	    	  id:pkMenu,
		    	    	  SortID:newSort,
		    	    	  type:'upDown'
		    	    },  
		    	    type:'post',  
		    	    cache:false,  
		    	    dataType:'json',  
		    	    success:function(map) {  
		    	    	if(map.success){		    	    		
		    	    		$('#tg').treegrid('reload');
		    	    	}		    	    	    	           
		    	    },  
		    	     error : function() {  
		    	          alert("异常！");  
		    	     }  
		    	});					
	           
	        } 
			
			function del(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {
			    		$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../ArticleCategory/delete.json',
							data:{ids:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									window.location.reload();  
									
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    			
				    },
				    cancelVal: '取消',
				    cancel: true //为true等价于function(){}
				});
			
          	} 
			
			function edit(index){  //编辑					
				art.dialog.open('../ArticleCategory/updateInterface.htm?type=edit&id='+index,{
					title: '',
					lock:true,
				  	width: '50%',
				    height: '70%'												   												   
				});
          	} 
			
			function addSub(index,levelID,fk_orgId){  //新增子集
				art.dialog.open('../ArticleCategory/addInterface.htm?type=addSub&parentID='+index+'&levelID='+levelID+'&fk_orgId='+fk_orgId,{
					title: '',
					lock:true,
				  	width: '50%',
				    height: '50%'												   												   
				});
          	} 			
		</script>	
	</head>
	<body>
		<div>					
			<table id="tg" width="100%" height="100%"></table>				
		</div>
	</body>
</html>